#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#     Filename @  private_attr.py
#       Author @  Huoty
#  Create date @  2016-07-23 11:21:26
#  Description @
# *************************************************************

class TestObj(object):
    tar = 1
    __far = tar
    __har = tar

    def foo(self):
        pass

    def too(self):
        pass

    def __hello(self):
        if hasattr(self, "__har"):
            print("------ in hello -------->", self.__har)

    def __world(self):
        pass

    def __getattr__(self, name):
        print('------', name)
        if name.startswith("__"):
            try:
                return getattr(self, "_TestObj" + name)
            except AttributeError:
                pass
        raise AttributeError(
            "'TestObj' object has no attribute '{}'".format(name)
        )


# Script starts from here

if __name__ == "__main__":
    to = TestObj()
    print(dir(to))
    print(to.__dict__)
    print(to.__far)
    print(hasattr(to, "__har"))
    to.__hello()
    # to.__ttt
    to._ttt
